package com.hyzh.hj212.dmo;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Map;

/**
 * @author songkui
 * @since 2024/6/27 22:18
 */
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class StatsDataVO {

    private Double standard; //标准
    private String[] item; //折线图： 数据项
    private double[] numerical; //折线图 ： 数值


    public static StatsDataVO ofNull(Double standard){
        StatsDataVO statsDataVO = new StatsDataVO();
        statsDataVO.setItem(new String[0]);
        statsDataVO.setNumerical(new double[0]);
        statsDataVO.setStandard(standard);
        return statsDataVO;
    }


    public static StatsDataVO ofOne(String ite, double v){
        StatsDataVO statsDataVO = new StatsDataVO();
        statsDataVO.setItem(new String[]{ite});
        statsDataVO.setNumerical(new double[]{v});
        return statsDataVO;
    }

    public static StatsDataVO ofMap(double standard, Map<String, Double> data){
        StatsDataVO statsDataVO = new StatsDataVO();
        statsDataVO.setStandard(standard);
        String[] item = new String[data.size()];
        double[] doubles = new double[data.size()];
        int i=0;
        for (Map.Entry<String, Double> entry : data.entrySet()){
            item[i] = entry.getKey();
            doubles[i] = entry.getValue();
            i++;
        }
        statsDataVO.setItem(item);
        statsDataVO.setNumerical(doubles);
        return statsDataVO;
    }

}
